<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

    <script type="text/javascript">
        $(function(){
            $("#articleDg").datagrid({
                url:"${pageContext.request.contextPath}/article/getArticleByPage",
                title:"文章列表",
                width:1200,
                pagination:true,//如果为true，则在DataGrid控件底部显示分页工具栏。默认为false
                onDblClickRow:function(rowIndex,rowData){  //双击打开修改对话框
                    $("#updateArticleDiv").dialog("open");
                    $("#updateArticleName").val(rowData.articleName);
                    $("#updateArticleImage").val(rowData.articleImage);
                    $("#updateArticleContent").val(rowData.articleContent);
                    $("#updateGuruId").val(rowData.guruId);
                    $("#articleId").val(rowData.articleId);  //
                },
                loadMsg:"拼命加载中...",// string  在从远程站点加载数据的时候显示提示消息
                toolbar:"#myToolbar7",//在<div>标签上定义工具栏
                columns:[[    //表格相当于二维数组，


                    {title:"编号",field:"articleId",checkbox:true},//一个{}表示一列
                    {title:"标题",field:"articleName"},
                    {title:"图片",field:"articleImage"},
                    {title:"内容",field:"articleContent"},
                    {title:"上师ID",field:"guruId"},
                    {title:"日期",field:"articleDate"},

                ]]

            });
            //添加对话框
            $("#addDiv").dialog({
                width:300,
                title:"添加对话框",
                height:200,
                closed:true,
                buttons:"#addDialogBtn2"  //添加按钮
            });
            //修改对话框
            $("#updateArticleDiv").dialog({
                width:300,
                title:"修改对话框",
                height:200,
                closed:true,
                buttons:"#updateDialogBtn2"  //修改按钮
            });
            $('#ss').searchbox({
                searcher:function(value){
                   //  alert(value);
                    $('#articleDg').datagrid('load', { "keyword": value });
                }
            });

        });
        function toOpenAddDialog(){
            // 1.打开添加对话框
            $("#addDiv").dialog("open");
        }
        function doAdd() {
            //通过form控件的submit方法提交表单
            $("#addForm").form("submit",{
                url:"${pageContext.request.contextPath}/article/add",
                success:function(data){
                    //alert(data);
                    //data就是一个json串
                    var jsObj = JSON.parse(data);
                    if(jsObj.isAdd){
                        //把添加对话框关闭掉
                        //把datagrid刷新
                        alert("添加成功");
                        $("#addDiv").dialog("close");
                        $("#articleDg").datagrid("reload");  // 重新载入当前页面数据
                    }else{
                        alert("添加失败，请确认");
                    }
                }
            });
        }


        /*修改的信息收集和提交*/
        function doUpdate() {
            //通过form控件的submit方法提交表单
            $("#updateForm2").form("submit",{
                url:"${pageContext.request.contextPath}/article/update",
                success:function(data){
                    // alert(data);
                    //data就是一个json串
                    var jsObj = JSON.parse(data);
                    if(jsObj.isUpdate){
                        //把修改对话框关闭掉
                        //把datagrid刷新
                        alert("修改成功");
                        $("#updateGuruDiv").dialog("close");
                        $("#articleDg").datagrid("reload");
                    }else{
                        alert("修改失败，请确认");
                    }
                }
            });
        }


        function qq(value,name){
            // alert(value+":"+name)
        }

        function doResetIndex() {
            $.ajax({
                url:"${pageContext.request.contextPath}/article/resetIndex",
                success:function (data) {
                    // alert(data.isResetIndex)
                }
            })
        }

    </script>



<table id="articleDg"></table>

<div id="myToolbar7">  <%--工具栏按钮--%>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" onclick="doMultiDelete()">批量删除</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="toOpenAddDialog()">添加</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" onclick="doResetIndex()">重置索引</a>
    <input id="ss" class="easyui-searchbox" style="width:200px"
           data-options="searcher:qq,prompt:'Please Input Value'">高级检索</input>
</div>



<div id="addDiv">
    <form id="addForm" method="post" >
        <%--<input type="hidden" name="id" id="id2"/>--%>
        文章标题：<input id="addArticleName" name="articleName"/><br/>
        image：<input id="addArticleImage" name="articleImage"/><br/>
            内容：<input id="addArticleContent" name="articleContent"/><br/>
        上师ID：<input id="addGuruId" name="guruId" /><br/>
        <!-- <input type="button" value="添加" onclick="doAdd()"/> -->
    </form>
</div>
<div id="updateArticleDiv">
    <form id="updateForm2" method="post" enctype="multipart/form-data">
        <input type="hidden" name="articleId" id="articleId"/>
        文章标题：<input id="updateArticleName" name="articleName"/><br/>
        image：<input id="updateArticleImage" name="articleImage"/><br/>
        内容：<input id="updateArticleContent" name="articleContent"/><br/>
        上师ID：<input id="updateGuruId" name="guruId" /><br/>
        <!-- <input type="button" value="修改" onclick="doUpdate()"/> -->
    </form>
</div>

<div id="addDialogBtn2"><%--对话框按钮--%>
    <a href="javascript:void(0)" onclick="doAdd()" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">添加</a>
</div>
<div id="updateDialogBtn2"><%--对话框按钮--%>
    <a href="javascript:void(0)" onclick="doUpdate()" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
</div>



